package com.guodu.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.guodu.base.BaseDao;
import com.guodu.dao.SupplierEvaluationDao;
import com.guodu.entity.SupplierEvaluation;
import com.guodu.entity.SupplierEvaluationStatus;
import com.guodu.entity.Units;
import com.guodu.vo.SupplierEvaluationQueryVo;

@Repository("supplierEvaluationDao")
public class SupplierEvaluationDaoImpl extends BaseDao implements SupplierEvaluationDao{

	
	public int findSizeByVo(
			SupplierEvaluationQueryVo supplierEvaluationQueryVo, Units units) {
		StringBuffer hql = new StringBuffer("select count(*) from SupplierEvaluation s where 1=1");
		if(supplierEvaluationQueryVo != null){
			 if(supplierEvaluationQueryVo.getDayStart()!= null && !supplierEvaluationQueryVo.getDayStart().trim().equals("")){
				 hql.append(" and s.evaluationTime >= TO_DATE('"+supplierEvaluationQueryVo.getDayStart()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");				 
			 }
			 if(supplierEvaluationQueryVo.getDayEnd()!= null && !supplierEvaluationQueryVo.getDayEnd().trim().equals("")){
				 hql.append(" and s.evaluationTime <= TO_DATE('"+supplierEvaluationQueryVo.getDayEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");				 
			 }
			 if( supplierEvaluationQueryVo.getProductName() != null && !supplierEvaluationQueryVo.getProductName().trim().equals("")){
					hql.append(" and s.productName like '%"+supplierEvaluationQueryVo.getProductName()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getIndustry() != null && !supplierEvaluationQueryVo.getIndustry().trim().equals("")){
					hql.append(" and s.industry like '%"+supplierEvaluationQueryVo.getIndustry()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getSupplierName() != null && !supplierEvaluationQueryVo.getSupplierName().trim().equals("")){
					hql.append(" and s.supplierName like '%"+supplierEvaluationQueryVo.getSupplierName()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getSupplierCode() != null && !supplierEvaluationQueryVo.getSupplierCode().trim().equals("")){
					hql.append(" and s.supplierCode like '%"+supplierEvaluationQueryVo.getSupplierCode()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationZl() != null && !supplierEvaluationQueryVo.getEvaluationZl().trim().equals("") ){
					hql.append(" and s.evaluationZl like '%"+supplierEvaluationQueryVo.getEvaluationZl()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationJhjd() != null && !supplierEvaluationQueryVo.getEvaluationJhjd().trim().equals("")){
					hql.append(" and s.evaluationJhjd like '%"+supplierEvaluationQueryVo.getEvaluationJhjd()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationShfw() != null && !supplierEvaluationQueryVo.getEvaluationShfw().trim().equals("")){
					hql.append(" and s.evaluationShfw like '%"+supplierEvaluationQueryVo.getEvaluationShfw()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationZh() != null && !supplierEvaluationQueryVo.getEvaluationZh().trim().equals("")){
					hql.append(" and s.evaluationZh like '%"+supplierEvaluationQueryVo.getEvaluationZh()+"%'");
			 }
			 if(supplierEvaluationQueryVo.getCreateTimeStart() != null && !supplierEvaluationQueryVo.getCreateTimeStart().trim().equals("")){
					hql.append(" and s.createTime >= TO_DATE('"+supplierEvaluationQueryVo.getCreateTimeStart()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			 }
			 if(supplierEvaluationQueryVo.getCreateTimeEnd() != null && !supplierEvaluationQueryVo.getCreateTimeEnd().trim().equals("")){
					hql.append(" and s.createTime <= TO_DATE('"+supplierEvaluationQueryVo.getCreateTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if(supplierEvaluationQueryVo.getFunitsId() != null){
					hql.append(" and  (unitsId = "+supplierEvaluationQueryVo.getFunitsId()+" or exists(select 1 from Units u where u.unitsId = s.unitsId and u.funitsId="+supplierEvaluationQueryVo.getFunitsId()+"))");
			}
			if(supplierEvaluationQueryVo.getUnitsId()!=null){
					hql.append(" and  unitsId = "+supplierEvaluationQueryVo.getUnitsId());
			}
			if(supplierEvaluationQueryVo.getStatus()!=null&&supplierEvaluationQueryVo.getStatus().trim().length()>0&&!supplierEvaluationQueryVo.getStatus().equals("10")){
				    hql.append(" and status ="+supplierEvaluationQueryVo.getStatus());
			}
		
		}		
//		if(units==null){
//			
//		}else if(units.getUnitsLevel()==1L){
//			hql.append(" and (exists(select 1 from UserInfo u where u.userId=s.createPeople and u.unitsId="+units.getUnitsId()+") or (status=3 or (status=0 and exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople))))");
//		}
//		else if(units.getUnitsLevel()==2L){
//			hql.append(" and (status=3 or (status=0 and exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople)))");
//		}
		if(units==null){
			
		}else if(units.getUnitsLevel()==1L){
			hql.append(" and (exists(select 1 from UserInfo u where u.userId=s.createPeople and u.unitsId="+units.getUnitsId()+") or  exists(select 1 from UserInfo u where u.userId=s.createPeople and exists(select 1 from Units us where us.unitsId = u.unitsId and us.funitsId= '"+units.getUnitsId()+"' )))");
		}else if(units.getUnitsLevel()==2L){
			//hql.append(" and (exists(select 1 from UserInfo u where u.userId=s.createPeople and u.unitsId="+units.getUnitsId()+") and ((status=0 and exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople)) or (status=3)))");	
			if(supplierEvaluationQueryVo.getUnitsId()!=null){
				hql.append(" and (unitsId="+supplierEvaluationQueryVo.getUnitsId()+" and (exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople) or(status=3)))");			
			}else{
				hql.append(" and ((unitsId="+supplierEvaluationQueryVo.getFunitsId()+" or exists(select 1 from Units us where us.unitsId = s.unitsId and us.funitsId = "+supplierEvaluationQueryVo.getFunitsId()+")) and (exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople) or(status=3)))");
			}		
		}
		
		
		
		return super.findInt(hql.toString());
	}

	
	public List<SupplierEvaluation> findByVo(
			SupplierEvaluationQueryVo supplierEvaluationQueryVo, Units units,
			int curPage, int pageSize) {
		StringBuffer hql = new StringBuffer("from SupplierEvaluation s where 1=1");
		if(supplierEvaluationQueryVo != null){
			 if(supplierEvaluationQueryVo.getDayStart()!= null && !supplierEvaluationQueryVo.getDayStart().trim().equals("")){
				 hql.append(" and s.evaluationTime >= TO_DATE('"+supplierEvaluationQueryVo.getDayStart()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");				 
			 }
			 if(supplierEvaluationQueryVo.getDayEnd()!= null && !supplierEvaluationQueryVo.getDayEnd().trim().equals("")){
				 hql.append(" and s.evaluationTime <= TO_DATE('"+supplierEvaluationQueryVo.getDayEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");				 
			 }
			 if( supplierEvaluationQueryVo.getProductName() != null && !supplierEvaluationQueryVo.getProductName().trim().equals("")){
					hql.append(" and s.productName like '%"+supplierEvaluationQueryVo.getProductName()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getIndustry() != null && !supplierEvaluationQueryVo.getIndustry().trim().equals("")){
					hql.append(" and s.industry like '%"+supplierEvaluationQueryVo.getIndustry()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getSupplierName() != null && !supplierEvaluationQueryVo.getSupplierName().trim().equals("")){
					hql.append(" and s.supplierName like '%"+supplierEvaluationQueryVo.getSupplierName()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getSupplierCode() != null && !supplierEvaluationQueryVo.getSupplierCode().trim().equals("")){
					hql.append(" and s.supplierCode like '%"+supplierEvaluationQueryVo.getSupplierCode()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationZl() != null && !supplierEvaluationQueryVo.getEvaluationZl().trim().equals("") ){
					hql.append(" and s.evaluationZl like '%"+supplierEvaluationQueryVo.getEvaluationZl()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationJhjd() != null && !supplierEvaluationQueryVo.getEvaluationJhjd().trim().equals("")){
					hql.append(" and s.evaluationJhjd like '%"+supplierEvaluationQueryVo.getEvaluationJhjd()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationShfw() != null && !supplierEvaluationQueryVo.getEvaluationShfw().trim().equals("")){
					hql.append(" and s.evaluationShfw like '%"+supplierEvaluationQueryVo.getEvaluationShfw()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationZh() != null && !supplierEvaluationQueryVo.getEvaluationZh().trim().equals("")){
					hql.append(" and s.evaluationZh like '%"+supplierEvaluationQueryVo.getEvaluationZh()+"%'");
			 }
			 if(supplierEvaluationQueryVo.getCreateTimeStart() != null && !supplierEvaluationQueryVo.getCreateTimeStart().trim().equals("")){
					hql.append(" and s.createTime >= TO_DATE('"+supplierEvaluationQueryVo.getCreateTimeStart()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			 }
			 if(supplierEvaluationQueryVo.getCreateTimeEnd() != null && !supplierEvaluationQueryVo.getCreateTimeEnd().trim().equals("")){
					hql.append(" and s.createTime <= TO_DATE('"+supplierEvaluationQueryVo.getCreateTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			 if(supplierEvaluationQueryVo.getFunitsId() != null){
					hql.append(" and  (unitsId = "+supplierEvaluationQueryVo.getFunitsId()+" or exists(select 1 from Units u where u.unitsId = s.unitsId and u.funitsId="+supplierEvaluationQueryVo.getFunitsId()+"))");
			}
			if(supplierEvaluationQueryVo.getUnitsId()!=null){
					hql.append(" and  unitsId = "+supplierEvaluationQueryVo.getUnitsId());
			}
			if(supplierEvaluationQueryVo.getStatus()!=null&&supplierEvaluationQueryVo.getStatus().trim().length()>0&&!supplierEvaluationQueryVo.getStatus().equals("10")){
				    hql.append(" and status ="+supplierEvaluationQueryVo.getStatus());
			}		
		}
//		if(units==null){
//			
//		}else if(units.getUnitsLevel()==1L){
//			hql.append(" and (exists(select 1 from UserInfo u where u.userId=s.createPeople and u.unitsId="+units.getUnitsId()+") or (status=3 or (status=0 and exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople))))");
//		}
//		else if(units.getUnitsLevel()==2L){
//			hql.append(" and (status=3 or (status=0 and exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople)))");
//		}
        if(units==null){
			
		}else if(units.getUnitsLevel()==1L){
			hql.append(" and (exists(select 1 from UserInfo u where u.userId=s.createPeople and u.unitsId="+units.getUnitsId()+") or  exists(select 1 from UserInfo u where u.userId=s.createPeople and exists(select 1 from Units us where us.unitsId = u.unitsId and us.funitsId= '"+units.getUnitsId()+"' )))");
		}else if(units.getUnitsLevel()==2L){
			//hql.append(" and (exists(select 1 from UserInfo u where u.userId=s.createPeople and u.unitsId="+units.getUnitsId()+") and ((status=0 and exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople)) or (status=3)))");	
			if(supplierEvaluationQueryVo.getUnitsId()!=null){
				hql.append(" and (unitsId="+supplierEvaluationQueryVo.getUnitsId()+" and (exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople) or(status=3)))");			
			}else{
				hql.append(" and ((unitsId="+supplierEvaluationQueryVo.getFunitsId()+" or exists(select 1 from Units us where us.unitsId = s.unitsId and us.funitsId = "+supplierEvaluationQueryVo.getFunitsId()+")) and (exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople) or(status=3)))");
			}		
		}
		hql.append(" order by createTime desc");		
		return super.findPages(hql.toString(), curPage, pageSize);
	}

	
	@SuppressWarnings("unchecked")
	public List<SupplierEvaluation> downLoad(SupplierEvaluationQueryVo supplierEvaluationQueryVo,Units units) {
		StringBuffer hql = new StringBuffer("from SupplierEvaluation s where 1=1");
		if(supplierEvaluationQueryVo != null){
			 if(supplierEvaluationQueryVo.getDayStart()!= null && !supplierEvaluationQueryVo.getDayStart().trim().equals("")){
				 hql.append(" and s.evaluationTime >= TO_DATE('"+supplierEvaluationQueryVo.getDayStart()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");				 
			 }
			 if(supplierEvaluationQueryVo.getDayEnd()!= null && !supplierEvaluationQueryVo.getDayEnd().trim().equals("")){
				 hql.append(" and s.evaluationTime <= TO_DATE('"+supplierEvaluationQueryVo.getDayEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");				 
			 }
			 if( supplierEvaluationQueryVo.getProductName() != null && !supplierEvaluationQueryVo.getProductName().trim().equals("")){
					hql.append(" and s.productName like '%"+supplierEvaluationQueryVo.getProductName()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getIndustry() != null && !supplierEvaluationQueryVo.getIndustry().trim().equals("")){
					hql.append(" and s.industry like '%"+supplierEvaluationQueryVo.getIndustry()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getSupplierName() != null && !supplierEvaluationQueryVo.getSupplierName().trim().equals("")){
					hql.append(" and s.supplierName like '%"+supplierEvaluationQueryVo.getSupplierName()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getSupplierCode() != null && !supplierEvaluationQueryVo.getSupplierCode().trim().equals("")){
					hql.append(" and s.supplierCode like '%"+supplierEvaluationQueryVo.getSupplierCode()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationZl() != null && !supplierEvaluationQueryVo.getEvaluationZl().trim().equals("") ){
					hql.append(" and s.evaluationZl like '%"+supplierEvaluationQueryVo.getEvaluationZl()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationJhjd() != null && !supplierEvaluationQueryVo.getEvaluationJhjd().trim().equals("")){
					hql.append(" and s.evaluationJhjd like '%"+supplierEvaluationQueryVo.getEvaluationJhjd()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationShfw() != null && !supplierEvaluationQueryVo.getEvaluationShfw().trim().equals("")){
					hql.append(" and s.evaluationShfw like '%"+supplierEvaluationQueryVo.getEvaluationShfw()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationZh() != null && !supplierEvaluationQueryVo.getEvaluationZh().trim().equals("")){
					hql.append(" and s.evaluationZh like '%"+supplierEvaluationQueryVo.getEvaluationZh()+"%'");
			 }
			 if(supplierEvaluationQueryVo.getCreateTimeStart() != null && !supplierEvaluationQueryVo.getCreateTimeStart().trim().equals("")){
					hql.append(" and s.createTime >= TO_DATE('"+supplierEvaluationQueryVo.getCreateTimeStart()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			 }
			 if(supplierEvaluationQueryVo.getCreateTimeEnd() != null && !supplierEvaluationQueryVo.getCreateTimeEnd().trim().equals("")){
					hql.append(" and s.createTime <= TO_DATE('"+supplierEvaluationQueryVo.getCreateTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			 if(supplierEvaluationQueryVo.getFunitsId() != null){
					hql.append(" and  (unitsId = "+supplierEvaluationQueryVo.getFunitsId()+" or exists(select 1 from Units u where u.unitsId = s.unitsId and u.funitsId="+supplierEvaluationQueryVo.getFunitsId()+"))");
			}
			if(supplierEvaluationQueryVo.getUnitsId()!=null){
					hql.append(" and  unitsId = "+supplierEvaluationQueryVo.getUnitsId());
			}
			if(supplierEvaluationQueryVo.getStatus()!=null&&supplierEvaluationQueryVo.getStatus().trim().length()>0&&!supplierEvaluationQueryVo.getStatus().equals("10")){
				    hql.append(" and status ="+supplierEvaluationQueryVo.getStatus());
			}		
		}
//		if(units==null){
//			
//		}else if(units.getUnitsLevel()==1L){
//			hql.append(" and (exists(select 1 from UserInfo u where u.userId=s.createPeople and u.unitsId="+units.getUnitsId()+") or (status=3 or (status=0 and exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople))))");
//		}
//		else if(units.getUnitsLevel()==2L){
//			hql.append(" and (status=3 or (status=0 and exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople)))");
//		}
		if(units==null){
			
		}else if(units.getUnitsLevel()==1L){
			hql.append(" and (exists(select 1 from UserInfo u where u.userId=s.createPeople and u.unitsId="+units.getUnitsId()+") or  exists(select 1 from UserInfo u where u.userId=s.createPeople and exists(select 1 from Units us where us.unitsId = u.unitsId and us.funitsId= '"+units.getUnitsId()+"' )))");
		}else if(units.getUnitsLevel()==2L){
			hql.append(" and (exists(select 1 from UserInfo u where u.userId=s.createPeople and u.unitsId="+units.getUnitsId()+") and ((status=0 and exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople)) or (status=3)))");
		}
		hql.append(" order by createTime desc");		
		return super.find(hql.toString());
	}
	@Override
	public void examinAll(SupplierEvaluationQueryVo supplierEvaluationQueryVo,
			Units units) {
		StringBuffer hql = new StringBuffer();
        if(units==null){
        	hql.append("update from SupplierEvaluation s set s.status=3 where s.status=0 ");
		}else if(units.getUnitsLevel()==1L){
			hql.append("update from SupplierEvaluation s set s.status=1 where s.status=0 ");
		}
        if(supplierEvaluationQueryVo != null){
			 if(supplierEvaluationQueryVo.getDayStart()!= null && !supplierEvaluationQueryVo.getDayStart().trim().equals("")){
				 hql.append(" and s.evaluationTime >= TO_DATE('"+supplierEvaluationQueryVo.getDayStart()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");				 
			 }
			 if(supplierEvaluationQueryVo.getDayEnd()!= null && !supplierEvaluationQueryVo.getDayEnd().trim().equals("")){
				 hql.append(" and s.evaluationTime <= TO_DATE('"+supplierEvaluationQueryVo.getDayEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");				 
			 }
			 if( supplierEvaluationQueryVo.getProductName() != null && !supplierEvaluationQueryVo.getProductName().trim().equals("")){
					hql.append(" and s.productName like '%"+supplierEvaluationQueryVo.getProductName()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getIndustry() != null && !supplierEvaluationQueryVo.getIndustry().trim().equals("")){
					hql.append(" and s.industry like '%"+supplierEvaluationQueryVo.getIndustry()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getSupplierName() != null && !supplierEvaluationQueryVo.getSupplierName().trim().equals("")){
					hql.append(" and s.supplierName like '%"+supplierEvaluationQueryVo.getSupplierName()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getSupplierCode() != null && !supplierEvaluationQueryVo.getSupplierCode().trim().equals("")){
					hql.append(" and s.supplierCode like '%"+supplierEvaluationQueryVo.getSupplierCode()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationZl() != null && !supplierEvaluationQueryVo.getEvaluationZl().trim().equals("") ){
					hql.append(" and s.evaluationZl like '%"+supplierEvaluationQueryVo.getEvaluationZl()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationJhjd() != null && !supplierEvaluationQueryVo.getEvaluationJhjd().trim().equals("")){
					hql.append(" and s.evaluationJhjd like '%"+supplierEvaluationQueryVo.getEvaluationJhjd()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationShfw() != null && !supplierEvaluationQueryVo.getEvaluationShfw().trim().equals("")){
					hql.append(" and s.evaluationShfw like '%"+supplierEvaluationQueryVo.getEvaluationShfw()+"%'");
			 }
			 if( supplierEvaluationQueryVo.getEvaluationZh() != null && !supplierEvaluationQueryVo.getEvaluationZh().trim().equals("")){
					hql.append(" and s.evaluationZh like '%"+supplierEvaluationQueryVo.getEvaluationZh()+"%'");
			 }
			 if(supplierEvaluationQueryVo.getCreateTimeStart() != null && !supplierEvaluationQueryVo.getCreateTimeStart().trim().equals("")){
					hql.append(" and s.createTime >= TO_DATE('"+supplierEvaluationQueryVo.getCreateTimeStart()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			 }
			 if(supplierEvaluationQueryVo.getCreateTimeEnd() != null && !supplierEvaluationQueryVo.getCreateTimeEnd().trim().equals("")){
					hql.append(" and s.createTime <= TO_DATE('"+supplierEvaluationQueryVo.getCreateTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			 if(supplierEvaluationQueryVo.getFunitsId() != null){
					hql.append(" and  (unitsId = "+supplierEvaluationQueryVo.getFunitsId()+" or exists(select 1 from Units u where u.unitsId = s.unitsId and u.funitsId="+supplierEvaluationQueryVo.getFunitsId()+"))");
			}
			if(supplierEvaluationQueryVo.getUnitsId()!=null){
					hql.append(" and  unitsId = "+supplierEvaluationQueryVo.getUnitsId());
			}
			if(supplierEvaluationQueryVo.getStatus()!=null&&supplierEvaluationQueryVo.getStatus().trim().length()>0&&!supplierEvaluationQueryVo.getStatus().equals("10")){
				    hql.append(" and status ="+supplierEvaluationQueryVo.getStatus());
			}		
		}
		if(units==null){
			
		}else if(units.getUnitsLevel()==1L){
			hql.append(" and (exists(select 1 from UserInfo u where u.userId=s.createPeople and u.unitsId="+units.getUnitsId()+") or  exists(select 1 from UserInfo u where u.userId=s.createPeople and exists(select 1 from Units us where us.unitsId = u.unitsId and us.funitsId= '"+units.getUnitsId()+"' )))");
		}else if(units.getUnitsLevel()==2L){
			hql.append(" and (exists(select 1 from UserInfo u where u.userId=s.createPeople and u.unitsId="+units.getUnitsId()+") and ((status=0 and exists(select 1 from UserInfo u where u.unitsId is null and u.userId = s.createPeople)) or (status=3)))");
		}
		super.executeUpdate(hql.toString());		
	}
	public void save(SupplierEvaluation supplierEvaluation) {
		super.save(supplierEvaluation);		
	}

	public void examine(String ids, Long status) {
		StringBuffer hql = new StringBuffer("update SupplierEvaluation set status =");
		hql.append(status);
		hql.append(" where supplierId in (");
		hql.append(ids);
		hql.append(")");
		super.executeUpdate(hql.toString());
		
	}

	public void delByIds(String[] ids) {
		super.deleteAllById(SupplierEvaluation.class,ids);
		
	}

	public SupplierEvaluation findById(String id) {
		
		return (SupplierEvaluation) super.findById(SupplierEvaluation.class,id);
	}
	public void update(SupplierEvaluation supplierEvaluation) {
		super.update(supplierEvaluation);
		
	}

	public void changeStatus(
			List<SupplierEvaluationStatus> supplierEvaluationStatusList) {
		super.saveAll(supplierEvaluationStatusList);
		
	}

	public List<SupplierEvaluationStatus> findStatus(String id) {
		
		return super.findByProperty(SupplierEvaluationStatus.class,"supplierId",id);
	}

	public void deleteById(String id) {
		super.delete(SupplierEvaluation.class, id);
		
	}


	




	
	
}
